package cn.wang.test;

import cn.wang.auth.pojo.UserInfo;
import cn.wang.cart.interceptor.CartInterceptor;
import cn.wang.cart.pojo.Cart;
import cn.wang.cart.service.CartService;
import com.netflix.discovery.converters.Auto;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class redis {

    @Autowired
    CartService cartService;
    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void setCart(){
        Cart cart = new Cart();
        cart.setSkuId(1L);
        cart.setTitle("title");
        cart.setPrice(100L);
        cart.setOwnSpec("asdfasdf");
        cart.setNum(21);
        cart.setImage("image");
        redisTemplate.opsForHash().put("test","1",cart);
    }
    @Test
    public void getCart(){
        HashOperations<String,String,Cart> hashOperations = redisTemplate.opsForHash();
        Cart test = hashOperations.get("test", "1");
        System.out.println(test);
    }
    @Test
    public void getCarts(){

        BoundHashOperations<String,String,Cart> ops = redisTemplate.boundHashOps(cartService.REDIS_CART_PREFIX + 31);
        List<Cart> carts = ops.values();
        carts.forEach(System.out::println);
    }
}
